﻿Imports System.Windows.Forms

Public Class 主父窗体

#Region "货管菜单"

    '菜单“品牌型号”
    Private Sub 品牌型号ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 品牌型号ToolStripMenuItem.Click

        If PinPaiform Is Nothing Then
            PinPaiform = New 品牌型号
            PinPaiform.MdiParent = Me
            PinPaiform.Show()
        Else
            PinPaiform.Focus()
            'MsgBox("已创建")
        End If

    End Sub

    '菜单“一般入货”
    Private Sub 一般入货ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 一般入货ToolStripMenuItem1.Click
        If CommoditIn Is Nothing Then
            CommoditIn = New 入货管理
            CommoditIn.MdiParent = Me
            CommoditIn.Show()
        Else
            CommoditIn.Focus()
            'MsgBox("已创建")
        End If
    End Sub
    Private Sub 一般入货ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 一般入货ToolStripMenuItem.Click
        一般入货ToolStripMenuItem1_Click(sender, e)
    End Sub

    '菜单“批量入货”
    Private Sub ToolStripButton2_ButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.ButtonClick
        If CommoMulIn Is Nothing Then
            CommoMulIn = New 批量入货
            CommoMulIn.MdiParent = Me
            CommoMulIn.Show()
        Else
            CommoMulIn.Focus()
            'MsgBox("已创建")
        End If
    End Sub
    Private Sub 批量入货ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 批量入货ToolStripMenuItem.Click
        ToolStripButton2_ButtonClick(sender, e)
    End Sub
    Private Sub 批量入货ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 批量入货ToolStripMenuItem1.Click
        ToolStripButton2_ButtonClick(sender, e)
    End Sub


    '菜单“出售管理”
    Private Sub 出售管理ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 出售管理ToolStripMenuItem.Click
        If Commodsell Is Nothing Then
            Commodsell = New 出售管理
            Commodsell.MdiParent = Me
            Commodsell.Show()
        Else
            Commodsell.Focus()
            'MsgBox("已创建")
        End If
    End Sub
    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        出售管理ToolStripMenuItem_Click(sender, e)
    End Sub

#End Region

#Region "维修菜单"

    '建立维修任务
    Private Sub 建立维修任务ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 建立维修任务ToolStripMenuItem.Click
        If StarRpForm Is Nothing Then
            StarRpForm = New 维修录入
            StarRpForm.MdiParent = Me
            StarRpForm.Show()
        Else
            StarRpForm.Focus()
            'MsgBox("已创建")
        End If
    End Sub
    Private Sub 维修录入ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 维修录入ToolStripMenuItem.Click
        建立维修任务ToolStripMenuItem_Click(sender, e)
    End Sub

    '结束维修任务
    Private Sub 结束维修任务ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 结束维修任务ToolStripMenuItem.Click
        If ResuRpForm Is Nothing Then
            ResuRpForm = New 维修结果
            ResuRpForm.MdiParent = Me
            ResuRpForm.Show()
        Else
            ResuRpForm.Focus()
            'MsgBox("已创建")
        End If
    End Sub
    Private Sub 维修结果ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 维修结果ToolStripMenuItem.Click
        结束维修任务ToolStripMenuItem_Click(sender, e)
    End Sub

    '任务参数预设
    Private Sub 任务参数预设ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 任务参数预设ToolStripMenuItem.Click
        If SettRPForm Is Nothing Then
            SettRPForm = New 参数设置
            SettRPForm.MdiParent = Me
            SettRPForm.Show()
        Else
            SettRPForm.Focus()
            'MsgBox("已创建")
        End If
    End Sub

    '维修记录
    Private Sub 维修记录查询ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 维修记录查询ToolStripMenuItem.Click
        If PrRecoForm Is Nothing Then
            PrRecoForm = New 维修记录
            PrRecoForm.MdiParent = Me
            PrRecoForm.Show()
        Else
            PrRecoForm.Focus()
            'MsgBox("已创建")
        End If
    End Sub

#End Region

#Region "用户菜单"

    '菜单“修改密码”
    Private Sub 修改密码ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 修改密码ToolStripMenuItem.Click

        If PWchangeFM Is Nothing Then
            PWchangeFM = New 修改密码
            PWchangeFM.MdiParent = Me
            PWchangeFM.Show()
        Else
            PWchangeFM.Focus()
            'MsgBox("已创建")
        End If

    End Sub

    '菜单“管理用户”
    Private Sub 管理用户ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 管理用户ToolStripMenuItem.Click
        If AccountMFM Is Nothing Then
            AccountMFM = New 用户管理
            AccountMFM.MdiParent = Me
            AccountMFM.Show()
        Else
            AccountMFM.Focus()
            'MsgBox("已创建")
        End If
    End Sub

#End Region

#Region "查看记录"

    '菜单“查看库存”
    Private Sub 库存ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 库存ToolStripMenuItem.Click
        If SearchForm Is Nothing Then
            SearchForm = New 查看库存
            SearchForm.MdiParent = Me
            SearchForm.Show()
        Else
            SearchForm.Focus()
            'MsgBox("已创建")
        End If
    End Sub
    Private Sub 查看库存ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 查看库存ToolStripMenuItem.Click
        库存ToolStripMenuItem_Click(sender, e)
    End Sub

    '菜单“查看库存”
    Private Sub 货流记录ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 货流记录ToolStripMenuItem.Click
        If LogSearchF Is Nothing Then
            LogSearchF = New 出售记录
            LogSearchF.MdiParent = Me
            LogSearchF.Show()
        Else
            LogSearchF.Focus()
            'MsgBox("已创建")
        End If
    End Sub
    Private Sub 出售记录ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 出售记录ToolStripMenuItem.Click
        货流记录ToolStripMenuItem_Click(sender, e)
    End Sub

    '删除记录
    Private Sub 删除记录ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 删除记录ToolStripMenuItem.Click
        If RecordDelF Is Nothing Then
            RecordDelF = New 记录删除
            RecordDelF.MdiParent = Me
            RecordDelF.Show()
        Else
            RecordDelF.Focus()
            'MsgBox("已创建")
        End If
    End Sub
    Private Sub 删除记录ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 删除记录ToolStripMenuItem1.Click
        删除记录ToolStripMenuItem_Click(sender, e)
    End Sub

    '订单记录
    Private Sub 单号记录ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 单号记录ToolStripMenuItem.Click
        If SelsRsForm Is Nothing Then
            SelsRsForm = New 订单记录
            SelsRsForm.MdiParent = Me
            SelsRsForm.Show()
        Else
            SelsRsForm.Focus()
            'MsgBox("已创建")
        End If
    End Sub
    Private Sub 单号记录ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 单号记录ToolStripMenuItem1.Click
        单号记录ToolStripMenuItem_Click(sender, e)
    End Sub

#End Region

    '隐蒧软件
    Private Sub 主父窗体_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        e.Cancel = True
        Me.Hide()
    End Sub

    '窗体加载
    Private Sub 主父窗体_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        TableBuilt()  '补入维修表
        TableBuilt2() '补入维修项（表）
        TableBuilt3() '补入维修员（表）

        If ManageRight Then
            管理用户ToolStripMenuItem.Visible = True
        Else
            管理用户ToolStripMenuItem.Visible = False
        End If

        If WriteRight Then
            入货管理ToolStripMenuItem.Enabled = True
            出售管理ToolStripMenuItem.Enabled = True
            品牌型号ToolStripMenuItem.Enabled = True
            ToolStripButton1.Enabled = True
            ToolStripButton2.Enabled = True
        Else
            入货管理ToolStripMenuItem.Enabled = False
            出售管理ToolStripMenuItem.Enabled = False
            品牌型号ToolStripMenuItem.Enabled = False
            ToolStripButton1.Enabled = False
            ToolStripButton2.Enabled = False
        End If

        If ReadRight Then
            查看库存ToolStripMenuItem.Enabled = True
            出售记录ToolStripMenuItem.Enabled = True
            货流记录ToolStripMenuItem.Enabled = True
            单号记录ToolStripMenuItem.Enabled = True
            单号记录ToolStripMenuItem1.Enabled = True
            库存ToolStripMenuItem.Enabled = True
        Else
            查看库存ToolStripMenuItem.Enabled = False
            出售记录ToolStripMenuItem.Enabled = False
            货流记录ToolStripMenuItem.Enabled = False
            单号记录ToolStripMenuItem.Enabled = False
            单号记录ToolStripMenuItem1.Enabled = False
            库存ToolStripMenuItem.Enabled = False
        End If

        If WriteRight And ReadRight Then
            结算ToolStripMenuItem.Visible = False  '功能去掉
            删除记录ToolStripMenuItem1.Visible = True
            删除记录ToolStripMenuItem.Visible = True
        Else
            结算ToolStripMenuItem.Visible = False
            删除记录ToolStripMenuItem1.Visible = False
            删除记录ToolStripMenuItem.Visible = False
        End If

        '选择数据库标志初始化
        DBchoose = "new"
        ToolStripButton4.ToolTipText = "现载常态数据库，点击切换到早期数据"

    End Sub

    '显示窗体
    Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
        Me.Show()
    End Sub
    Private Sub 恢复窗口ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 恢复窗口ToolStripMenuItem.Click
        Me.Show()
    End Sub

    '关闭软件
    Private Sub 关闭软件ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 关闭软件ToolStripMenuItem.Click
        NotifyIcon1.Visible = False
        End
        Application.Exit()
    End Sub

    '菜单结算项
    Private Sub 结算ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 结算ToolStripMenuItem.Click
        If CalulaForm Is Nothing Then
            CalulaForm = New 结算窗体
            CalulaForm.MdiParent = Me
            CalulaForm.Show()
        Else
            CalulaForm.Focus()
            'MsgBox("已创建")
        End If
    End Sub

    '菜单设置项
    Private Sub 设置ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 设置ToolStripMenuItem.Click
        If OldBbSForm Is Nothing Then
            OldBbSForm = New 旧数据库
            OldBbSForm.MdiParent = Me
            OldBbSForm.Show()
        Else
            OldBbSForm.Focus()
            'MsgBox("已创建")
        End If
    End Sub

    '补入维修表
    Private Sub TableBuilt()

        Dim Flag1 As Boolean   '维修表是否存在

        '判断单号表是否存在
        Try
            Dim SqlSearch As String = "select * from 维修表"
            Dim ds11 As DataSet = SQLtoDataSet(SqlSearch)
            If ds11.Tables.Count > 0 Then
                Flag1 = True     '存在
            End If
        Catch ex As Exception
            Flag1 = False        '不存在
        End Try

        '建表完成
        If Not Flag1 Then
            Dim SqlTableCA As String = ""
            SqlTableCA += "create table 维修表 ( "
            SqlTableCA += "ID integer IDENTITY (1,1) PRIMARY KEY ,"
            SqlTableCA += "品牌 char(20) not null,"
            SqlTableCA += "型号 char(20) not null,"
            SqlTableCA += "维修单号 char(20) not null,"
            SqlTableCA += "始修日期 date not null,"
            SqlTableCA += "修讫日期 date,"
            SqlTableCA += "维修员 char(20) not null,"
            SqlTableCA += "项目 char(200) not null,"
            SqlTableCA += "电话 char(20) not null,"
            SqlTableCA += "地址 char(200),"
            SqlTableCA += "维修结果 char(200),"
            SqlTableCA += "预测费用 money,"
            SqlTableCA += "实收费用 money,"
            SqlTableCA += "修讫备注 char(200),"
            SqlTableCA += "备注 char(200))"
            SQLupdata(SqlTableCA)
        End If

    End Sub

    '补入维修项（表）
    Private Sub TableBuilt2()

        Dim Flag1 As Boolean   '维修项（表）是否存在

        '判断维修项（表）是否存在
        Try
            Dim SqlSearch As String = "select * from 维修项"
            Dim ds11 As DataSet = SQLtoDataSet(SqlSearch)
            If ds11.Tables.Count > 0 Then
                Flag1 = True     '存在
            End If
        Catch ex As Exception
            Flag1 = False        '不存在
        End Try

        '建表完成
        If Not Flag1 Then
            Dim SqlTableCA As String = ""
            SqlTableCA += "create table 维修项 ( "
            SqlTableCA += "ID integer IDENTITY (1,1) PRIMARY KEY ,"
            SqlTableCA += "项目 char(200) not null,"
            SqlTableCA += "预测费用 money,"
            SqlTableCA += "备注 char(200))"
            SQLupdata(SqlTableCA)
        End If

    End Sub

    '补入维修员（表）
    Private Sub TableBuilt3()

        Dim Flag1 As Boolean   '维修员（表）是否存在

        '判断维修员（表）是否存在
        Try
            Dim SqlSearch As String = "select * from 维修员"
            Dim ds11 As DataSet = SQLtoDataSet(SqlSearch)
            If ds11.Tables.Count > 0 Then
                Flag1 = True     '存在
            End If
        Catch ex As Exception
            Flag1 = False        '不存在
        End Try

        '建表完成
        If Not Flag1 Then
            Dim SqlTableCA As String = ""
            SqlTableCA += "create table 维修员( "
            SqlTableCA += "ID integer IDENTITY (1,1) PRIMARY KEY ,"
            SqlTableCA += "维修员 char(20) not null,"
            SqlTableCA += "备注 char(200))"
            SQLupdata(SqlTableCA)
        End If

    End Sub

    '切换数据库
    Private Sub ToolStripButton4_Click(sender As Object, e As EventArgs) Handles ToolStripButton4.Click

        If DBchoose = "new" Then
            '判断是否已设置
            If Old_dbConnectionString <> "NotSet" Then
                cnn = getAccessConnection(Old_dbConnectionString)
            Else
                MessageBox.Show("未设置早期数据，请先设置")
                Exit Sub
            End If

            '按扭状态切换
            ToolStripButton4.Image = Image.FromFile(apps + "\skin\DataChoose_Old.png")
            ToolStripButton4.ToolTipText = "现载早期数据库，不能用于销售，点击切换销售用的数据库"

            '控件状态切换
            CtrlChange()

            DBchoose = "old"

        Else
            '切换连接
            cnn = getAccessConnection(New_dbConnectionString)
            '按扭状态切换
            ToolStripButton4.Image = Image.FromFile(apps + "\skin\DataChoose_New.png")
            ToolStripButton4.ToolTipText = "现载常态数据库，点击切换到早期数据"
            '控件状态切换
            CtrlChange()

            DBchoose = "new"

        End If

    End Sub
    '切换数据库后，限制操作
    Private Sub CtrlChange()
        If DBchoose = "new" Then
            CommMenuItem.Enabled = False
            维修WToolStripMenuItem.Enabled = False
            用户ToolStripMenuItem.Enabled = False
            结算ToolStripMenuItem.Enabled = False
            设置ToolStripMenuItem.Enabled = False
            ToolStripButton1.Enabled = False
            ToolStripButton2.Enabled = False
            ToolStripButton3.Enabled = False
            查看库存ToolStripMenuItem.Enabled = False
            库存ToolStripMenuItem.Enabled = False


        Else
            CommMenuItem.Enabled = True
            维修WToolStripMenuItem.Enabled = True
            用户ToolStripMenuItem.Enabled = True
            结算ToolStripMenuItem.Enabled = True
            设置ToolStripMenuItem.Enabled = True
            ToolStripButton1.Enabled = True
            ToolStripButton2.Enabled = True
            ToolStripButton3.Enabled = True
            查看库存ToolStripMenuItem.Enabled = True
            库存ToolStripMenuItem.Enabled = True
        End If

        '所有窗体关闭
        If PinPaiform IsNot Nothing Then PinPaiform.Close()             '品牌型号
        If CommoditIn IsNot Nothing Then CommoditIn.Close()             '入货管理
        If CommoMulIn IsNot Nothing Then CommoMulIn.Close()             '批量入货
        If Commodsell IsNot Nothing Then Commodsell.Close()             '出售管理

        If PWchangeFM IsNot Nothing Then PWchangeFM.Close()             '修改密码
        If AccountMFM IsNot Nothing Then AccountMFM.Close()             '用户管理

        If SearchForm IsNot Nothing Then SearchForm.Close()             '查看库存
        If LogSearchF IsNot Nothing Then LogSearchF.Close()             '出售记录

        If CalulaForm IsNot Nothing Then CalulaForm.Close()             '出售记录
        If RecordDelF IsNot Nothing Then RecordDelF.Close()             '记录删除

        If StarRpForm IsNot Nothing Then StarRpForm.Close()             '维修录入
        If ResuRpForm IsNot Nothing Then ResuRpForm.Close()             '维修结果
        If SettRPForm IsNot Nothing Then SettRPForm.Close()             '维修设置
        If PrRecoForm IsNot Nothing Then PrRecoForm.Close()             '维修记录

        If SelsRsForm IsNot Nothing Then SelsRsForm.Close()             '订单记录   
        If OldBbSForm IsNot Nothing Then OldBbSForm.Close()             '订单记录   

    End Sub

End Class
